using System;
using BruteForce.UserInterface.Abstracts;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace BruteForce.UserInterface.UIControls
{
    public class DynamicImage : AbstractUIControl
    {
        private Texture2D _image   ;
        delegate Texture2D DelegateFunction();
        private DelegateFunction _function;

        public DynamicImage(Texture2D image, string name, Rectangle surroundingRectangle, Func<Texture2D> method)
            : base(name, surroundingRectangle)
        {
            _image = image;
            _function = new DelegateFunction(method);
        }

        public override void Update()
        {
            _image = _function();
        }

        public override void Draw(GameTime gameTime)
        {
            if (_image!=null)
                BFGame.SpriteBatch.Draw(_image, CurrentUIcontrolRectangle, Color.White);
        }
    }
}